package com.powernode.interceptor;


import com.powernode.pojo.FloorAdmin;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author 姚崇崇
 */
@Component
public class SessionTimeoutInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        // 从session中获取用户信息
        FloorAdmin floorAdmin = (FloorAdmin) session.getAttribute("floorAdmin");

        // session过期
        if(floorAdmin == null){
            // 通过接口跳转登录页面
            response.sendRedirect("/login");
            return false;
        }else{
            return true;
        }
    }
}
